/**
 * Created by Administrator on 2017/8/9 0009.
 */
var shebeiFormatter = function(value,row,index){
    return ['<a href="javascript:void(0)" class="xjjilu">巡检记录</a>'+'&nbsp&nbsp&nbsp'+'<a href="javascript:void(0)" class="gzjilu">故障记录</a>'].join('');
}

var stateFormatter = function(value,row,index){

    if(value==1){
        return ['<a href="javascript:void(0)">正常</a>'].join('');
    }else if(value==0){
        return ['<a href="javascript:void(0)" style="color:red">维修</a>'].join();
    }

}

window.shebeiEvents={
    'click .xjjilu':function(e,value,row,index){
        showModel("xjjilu-div");
        var url = $().AbsUrlParse("/web/inspection/xjjilu?id="+value);
        $("#xjtable").bootstrapTable("refresh",{url:url});

    },
    'click .gzjilu':function(e,value,row,index){
        showModel("gzjilu-div");
        var url = $().AbsUrlParse("/web/inspection/gzjilu?id="+value);
        $("#gztable").bootstrapTable("refresh",{url:url});
    }
}


bindClick("#xjSearBtn",function(){
    //得到查询的信息
    var xjtimeSear = $("input[name=xjtimeSear]").val();
    var xjstart = "", xjend = "";
    if (xjtimeSear != null) {
        xjstart = xjtimeSear.split(" - ")[0];
        xjend = xjtimeSear.split(" - ")[1];
    }


    var wName = $("select[name=wName]").val();
    var xjcycleSear = $("select[name=xjcycleSear]").val();
    var xjmachnameSear = $("input[name=xjmachnameSear]").val();

    var url=$().AbsUrlParse("/web/motoroom/shebeiQuery?xjstart="+xjstart+"&xjend="+xjend+"&wName="+wName+"&xjcycleSear="+xjcycleSear+"&xjmachnameSear="+xjmachnameSear);
    $("#table").bootstrapTable("refresh",{url:url});

});


$.post($().AbsUrlParse("/web/motoroom/xjshebeiiPositionSelect"),{

},function(data){


    var datas = data.res.data;
    var selects = "<select class='form-control' name='wName'><option value=''>请输入位置</option>";
    for(var i=0;i<datas.length;i++){
        var val = datas[i].wName;
        selects+= "<option name="+val+">"+val+"</option>"
    }
    selects+="</select>"
    $("#postionSelect").html(selects);
});




bindClick("#digui",function(){
    comment.showOperationTips("你真要查找吗？",function(){
        comment.post($().AbsUrlParse("/web/inspection/digui"),function(data){
            alert(11);
        });
    })
})



//添加设备弹出的对话框
bindClick("#addshebei",function(){
    showModel("addshebei-div");
    //添加位置
    $.post($().AbsUrlParse("/web/deviceseat/diguiRealPath"),function(data){
        var datas = data.res.data;
        var options = "";
        options+="<select name='addweiName' class='form-control'>";
        for(var i=0;i<datas.length;i++){
            var singleData = datas[i];
            if(singleData.realPath!=""){
                var nameandid = singleData.realPath+'&&'+singleData.id;
                options+="<option name="+nameandid+">"+singleData.realPath+"</option>";
            }
        }
        options+="</select>"
        var parent = $("#wNameOptions").html(options);
    });
})


bindClick("#addsubmit",function(){

    var addmotorName = $("input[name=addmotorname]").val();
    var addmotortype =$("select[name=addmotortype]").val();
    var addweiName = $("select[name=addweiName] option:checked").attr('name');
    var addcheckCycle = $("select[name=addcheckCycle]").val();
    addweiName = addweiName.trim();
    if(addmotorName==""||addcheckCycle==""||addweiName==""||addmotortype){
        hint("表单填写不完整");
        return false;
    }



    comment.post($().AbsUrlParse("/web/motoroom/addSheBei"),{
        addmotorName:addmotorName,
        addmotortype:addmotortype,
        addweiName:addweiName,
        addcheckCycle:addcheckCycle
    },function(data){

    });


})








//初始化页面的时候运行该函数
$(function () {
    initDateRange();
});

function initDateRange() {
    $(".rangedate").daterangepicker({
        "autoApply": true,
        "locale": {
            "applyLabel": "确定",
            "cancelLabel": "取消",
            "fromLabel": "开始",
            "toLabel": "结束",
            "customRangeLabel": "Custom",
            "weekLabel": "周",
            "daysOfWeek": [
                "日",
                "一",
                "二",
                "三",
                "四",
                "五",
                "六"
            ],
            "monthNames": [
                "1月",
                "2月",
                "3月",
                "4月",
                "5月",
                "6月",
                "7月",
                "8月",
                "9月",
                "10月",
                "11月",
                "12月"
            ],
            "cancelLabel": '清空',
            "opens": "right"
        },
        "format": "YYYY-MM-DD"
    }).on('cancel.daterangepicker', function (ev, picker) {
        $(this).val('');
    });
}